package org.springblade.common.listener;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.spi.LoggerContextListener;
import ch.qos.logback.core.Context;
import ch.qos.logback.core.spi.ContextAwareBase;
import ch.qos.logback.core.spi.LifeCycle;
import org.springblade.common.utils.PlumePropsUtil;
import org.springblade.core.tool.utils.StringUtil;

/**
 * @Description plumelog logback监听类
 * @Author ysq
 * @Date 2024/1/30
 */
public class PlumeLogStartupListener extends ContextAwareBase implements LoggerContextListener, LifeCycle {

	@Override
	public void start() {
		Context context = getContext();
		context.putProperty("PLUME_MODE", "FALSE");
		context.putProperty("PLUME_STDOUT_APPENDER", "STDOUT");
		context.putProperty("PLUME_ONLINE_ENV", "TRUE");
		String redisHost = PlumePropsUtil.getRedisHost();
		if (StringUtil.isNotBlank(redisHost)) {
			context.putProperty("PLUME_MODE", "TRUE");
			context.putProperty("PLUME_STDOUT_APPENDER", "PLUME_LOG");
			context.putProperty("PLUME_ONLINE_ENV", PlumePropsUtil.getOnlineEnv());
			context.putProperty("PLUME_REDIS_HOST", redisHost);
			context.putProperty("PLUME_REDIS_AUTH", PlumePropsUtil.getRedisAuth());
		}
	}

	@Override
	public void stop() {

	}

	@Override
	public boolean isStarted() {
		return false;
	}

	@Override
	public boolean isResetResistant() {
		return false;
	}

	@Override
	public void onStart(LoggerContext context) {

	}

	@Override
	public void onReset(LoggerContext context) {

	}

	@Override
	public void onStop(LoggerContext context) {

	}

	@Override
	public void onLevelChange(Logger logger, Level level) {

	}
}
